//
// Created by wlk12 on 2024/3/3.
//

#pragma once
#include <iostream>
#include <vector>

struct Node
{
    int value{};
    Node* next{};

    Node() = default;
    explicit Node(int value) : value(value) {}
    Node(int value, Node* next) : value(value), next(next) {}
};

void printList(const char* name, Node* list)
{
    std::cout << name << ": ";
    if (list == nullptr)
    {
        std::cout << "null" << std::endl;
    }

    while (list != nullptr)
    {
        std::cout << list->value << ", ";
        list = list->next;
    }
    std::cout << std::endl;
}

Node* createList(const std::vector<int>& nums)
{
    Node list;
    Node* tail = &list;
    for (const auto n : nums) {
        tail->next = new Node{n};
        tail = tail->next;
    }
    return list.next;
}

void deleteList(Node* head)
{
    while (head != nullptr)
    {
        auto node = head;
        head = head->next;
        delete node;
    }
}